﻿using System;
using HslCommunication.Core;

namespace HslCommunication.MQTT
{
	/// <summary>
	/// 连接MQTT服务器的一些参数信息，适用<see cref="T:HslCommunication.MQTT.MqttClient" />消息发布订阅客户端以及<see cref="T:HslCommunication.MQTT.MqttSyncClient" />同步请求客户端。<br />
	/// Some parameter information for connecting to the MQTT server is applicable to the <see cref="T:HslCommunication.MQTT.MqttClient" /> message publishing and subscription client and the <see cref="T:HslCommunication.MQTT.MqttSyncClient" /> synchronization request client.
	/// </summary>
	// Token: 0x020000C0 RID: 192
	public class MqttConnectionOptions
	{
		/// <summary>
		/// 实例化一个默认的对象<br />
		/// Instantiate a default object
		/// </summary>
		// Token: 0x06000E3F RID: 3647 RVA: 0x000540C8 File Offset: 0x000522C8
		public MqttConnectionOptions()
		{
			this.ClientId = string.Empty;
			this.IpAddress = "127.0.0.1";
			this.Port = 1883;
			this.KeepAlivePeriod = TimeSpan.FromSeconds(100.0);
			this.KeepAliveSendInterval = TimeSpan.FromSeconds(30.0);
			this.CleanSession = true;
			this.ConnectTimeout = 5000;
		}

		/// <summary>
		/// Mqtt服务器的ip地址<br />
		/// IP address of Mqtt server
		/// </summary>
		// Token: 0x17000213 RID: 531
		// (get) Token: 0x06000E40 RID: 3648 RVA: 0x0005414A File Offset: 0x0005234A
		// (set) Token: 0x06000E41 RID: 3649 RVA: 0x00054152 File Offset: 0x00052352
		public string IpAddress
		{
			get
			{
				return this.ipAddress;
			}
			set
			{
				this.ipAddress = HslHelper.GetIpAddressFromInput(value);
			}
		}

		/// <summary>
		/// 端口号。默认1883<br />
		/// The port number. Default 1883
		/// </summary>
		// Token: 0x17000214 RID: 532
		// (get) Token: 0x06000E42 RID: 3650 RVA: 0x00054161 File Offset: 0x00052361
		// (set) Token: 0x06000E43 RID: 3651 RVA: 0x00054169 File Offset: 0x00052369
		public int Port { get; set; }

		/// <summary>
		/// 客户端的id的标识<br />
		/// ID of the client
		/// </summary>
		/// <remarks>
		/// 实际在传输的时候，采用的是UTF8编码的方式来实现。
		/// </remarks>
		// Token: 0x17000215 RID: 533
		// (get) Token: 0x06000E44 RID: 3652 RVA: 0x00054172 File Offset: 0x00052372
		// (set) Token: 0x06000E45 RID: 3653 RVA: 0x0005417A File Offset: 0x0005237A
		public string ClientId { get; set; }

		/// <summary>
		/// 连接到服务器的超时时间，默认是5秒，单位是毫秒<br />
		/// The timeout period for connecting to the server, the default is 5 seconds, the unit is milliseconds
		/// </summary>
		// Token: 0x17000216 RID: 534
		// (get) Token: 0x06000E46 RID: 3654 RVA: 0x00054183 File Offset: 0x00052383
		// (set) Token: 0x06000E47 RID: 3655 RVA: 0x0005418B File Offset: 0x0005238B
		public int ConnectTimeout { get; set; }

		/// <summary>
		/// 登录服务器的凭证，包含用户名和密码，可以为空<br />
		/// The credentials for logging in to the server, including the username and password, can be null
		/// </summary>
		// Token: 0x17000217 RID: 535
		// (get) Token: 0x06000E48 RID: 3656 RVA: 0x00054194 File Offset: 0x00052394
		// (set) Token: 0x06000E49 RID: 3657 RVA: 0x0005419C File Offset: 0x0005239C
		public MqttCredential Credentials { get; set; }

		/// <summary>
		/// 设置的参数，最小单位为1s，当超过设置的时间间隔没有发送数据的时候，必须发送PINGREQ报文，否则服务器认定为掉线。<br />
		/// The minimum unit of the set parameter is 1s. When no data is sent beyond the set time interval, the PINGREQ message must be sent, otherwise the server considers it to be offline.
		/// </summary>
		/// <remarks>
		/// 保持连接（Keep Alive）是一个以秒为单位的时间间隔，表示为一个16位的字，它是指在客户端传输完成一个控制报文的时刻到发送下一个报文的时刻，
		/// 两者之间允许空闲的最大时间间隔。客户端负责保证控制报文发送的时间间隔不超过保持连接的值。如果没有任何其它的控制报文可以发送，
		/// 客户端必须发送一个PINGREQ报文，详细参见 [MQTT-3.1.2-23]
		/// </remarks>
		// Token: 0x17000218 RID: 536
		// (get) Token: 0x06000E4A RID: 3658 RVA: 0x000541A5 File Offset: 0x000523A5
		// (set) Token: 0x06000E4B RID: 3659 RVA: 0x000541AD File Offset: 0x000523AD
		public TimeSpan KeepAlivePeriod { get; set; }

		/// <summary>
		/// 获取或是设置心跳时间的发送间隔。默认30秒钟<br />
		/// Get or set the heartbeat time interval. 30 seconds by default
		/// </summary>
		// Token: 0x17000219 RID: 537
		// (get) Token: 0x06000E4C RID: 3660 RVA: 0x000541B6 File Offset: 0x000523B6
		// (set) Token: 0x06000E4D RID: 3661 RVA: 0x000541BE File Offset: 0x000523BE
		public TimeSpan KeepAliveSendInterval { get; set; }

		/// <summary>
		/// 是否清理会话，如果清理会话（CleanSession）标志被设置为1，客户端和服务端必须丢弃之前的任何会话并开始一个新的会话。
		/// 会话仅持续和网络连接同样长的时间。与这个会话关联的状态数据不能被任何之后的会话重用 [MQTT-3.1.2-6]。默认为清理会话。<br />
		/// Whether to clean the session. If the CleanSession flag is set to 1, the client and server must discard any previous session and start a new session. 
		/// The session only lasts as long as the network connection. The state data associated with this session cannot be reused by any subsequent sessions [MQTT-3.1.2-6]. 
		/// The default is to clean up the session.
		/// </summary>
		// Token: 0x1700021A RID: 538
		// (get) Token: 0x06000E4E RID: 3662 RVA: 0x000541C7 File Offset: 0x000523C7
		// (set) Token: 0x06000E4F RID: 3663 RVA: 0x000541CF File Offset: 0x000523CF
		public bool CleanSession { get; set; }

		// Token: 0x040003CF RID: 975
		private string ipAddress = "127.0.0.1";
	}
}
